home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / misc / RecentScript.lha / RecentScript / RecentScriptCmd.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1997-07-10  |  20.9 KB  |  852 lines

  1. /*****
  2.   $VER: RecentScript Commands 1.3 (9.7.97) ©Arndt van der Molen
  3.  
  4.  
  5.                    RecentScript Commands
  6.  
  7.   is a MUIRexx subapplication and can not be started directly.
  8.  
  9.   It is called only from the starter application.
  10. *****/
  11.  
  12.  
  13.  
  14. /* Change to path with trailing ':' or '/' where this script resides */
  15.  
  16. srcdir = 'MUIREXX:RecentScript/'
  17.  
  18.  
  19.  
  20. /* !!! NOTHING TO CHANGE BELOW THIS LINE !!! */
  21.  
  22. MUIV_List_Select_Off      =  0
  23. MUIV_List_Select_On       =  1
  24.  
  25. OPTIONS RESULTS
  26.  
  27. PARSE ARG portname cmd1 cmd2 '['cmd3']'
  28.  
  29.  
  30. cmd2 = STRIP(cmd2)
  31.  
  32. PRAGMA('Directory',srcdir)   /* Set current directory */
  33.  
  34. ADDRESS VALUE portname
  35.  
  36. IF ~SHOW('l', "rexxdossupport.library") THEN DO
  37.   IF ~ADDLIB('rexxdossupport.library',0,-30,0) THEN DO
  38.     request ID RECSCRWIN TITLE '"Library Error"' GADGETS '"_OK"' STRING "Could not load 'rexxdossupport.library'"
  39.     RETURN
  40.   END
  41. END
  42.  
  43. SELECT
  44.   
  45.   WHEN cmd1 = 'ADD'         THEN CALL addentries
  46.  
  47.   WHEN cmd1 = 'CLR'         THEN CALL clearlist cmd2
  48.  
  49.   WHEN cmd1 = 'DEL'         THEN CALL delentry
  50.  
  51.   WHEN cmd1 = 'LOAD'        THEN CALL loadindex cmd2 cmd3
  52.  
  53.   WHEN cmd1 = 'MINUS'       THEN CALL patternentries MUIV_List_Select_Off
  54.  
  55.   WHEN cmd1 = 'PLUS'        THEN CALL patternentries MUIV_List_Select_On
  56.  
  57.   WHEN cmd1 = 'SAVE'        THEN CALL savelist
  58.  
  59.   WHEN cmd1 = 'SETBAT'      THEN CALL batchsettingopen '['cmd3']'
  60.  
  61.   WHEN cmd1 = 'SETBATHDL'   THEN CALL batchsettinghandle cmd2 '['cmd3']'
  62.  
  63.   WHEN cmd1 = 'TEST'        THEN CALL testprocedure
  64.  
  65.   OTHERWISE DO
  66.     request ID RECSCRWIN TITLE '"Internal Error"' GADGETS '"_OK"' STRING '"Unsupport command 'cmd1 cmd2 cmd3'"'
  67.   END
  68. END
  69.  
  70. RETURN
  71.  
  72.  
  73.  
  74. /* --------------------------------------------------------- */
  75. /* Add all selected entries from the LST_ALL to the LST_SEL  */
  76. /* --------------------------------------------------------- */
  77.  
  78. addentries: PROCEDURE
  79.  
  80. MUIA_List_Quiet           = '0x8042d8c7'
  81. MUIM_Busy_Move            = '0x80020001'
  82. MUIV_List_Insert_Bottom   = -3
  83.  
  84.  
  85. list ID LST_SEL ATTRS MUIA_List_Quiet 1
  86.  
  87. DO FOREVER
  88.  
  89.   list ID LST_ALL
  90.   entry = RESULT
  91.  
  92.   IF entry = '' THEN LEAVE
  93.  
  94.   method ID CLS_BUSY MUIM_Busy_Move
  95.  
  96.   list ID LST_SEL NODUP POS MUIV_List_Insert_Bottom INSERT STRING entry
  97. END
  98.  
  99. list ID LST_SEL ATTRS MUIA_List_Quiet 0
  100.  
  101. RETURN
  102.  
  103.  
  104.  
  105. /* --------------------------------------------------------- */
  106. /* Delete selected entry from the LST_SEL                    */
  107. /* --------------------------------------------------------- */
  108.  
  109. delentry: PROCEDURE
  110.  
  111. MUIA_List_Active          = '0x8042391c'
  112.  
  113. list ID LST_SEL ATTRS MUIA_List_Active
  114. position = RESULT
  115.  
  116. list ID LST_SEL POS position STRING
  117.  
  118. RETURN
  119.  
  120.  
  121.  
  122. /* --------------------------------------------------------- */
  123. /* Load specified AmiNet index file into specified listview  */
  124. /* --------------------------------------------------------- */
  125.  
  126. loadindex: PROCEDURE EXPOSE srcdir
  127.  
  128. parse arg listid ' ' filename
  129.  
  130. MUIA_List_Quiet           = '0x8042d8c7'
  131. MUIM_Busy_Move            = '0x80020001'
  132. ASLFR_InitialDrawer       = '0x80080009'
  133. MUIV_List_Insert_Bottom   = -3
  134.  
  135.  
  136. IF filename = '' THEN DO
  137.  
  138.   OPTIONS FAILAT 11
  139.   aslrequest ID RECSCRWIN TITLE '"Load AmiNet index file..."' ATTRS ASLFR_InitialDrawer srcdir
  140.   returncode = RC
  141.   filename   = RESULT
  142.   OPTIONS FAILAT 10
  143.  
  144.   IF returncode ~= 0 | filename = '' THEN DO
  145.     RETURN
  146.   END
  147. END
  148.  
  149. IF OPEN(indexhandle, filename, 'R') THEN DO
  150.  
  151.   list ID listid ATTRS MUIA_List_Quiet 1
  152.  
  153.   DO UNTIL EOF(indexhandle)
  154.  
  155.     method ID CLS_BUSY MUIM_Busy_Move
  156.  
  157.     line = READLN(indexhandle)
  158.  
  159.     /* Check if the line is an AmiNet Index line */
  160.  
  161.     slashposition = POS('/',line)
  162.  
  163.     /* This check must be edited if the format of the index file changes */
  164.     IF    (SUBSTR(line,34,1) = 'K' | SUBSTR(line,34,1) = 'M'),
  165.         & SUBSTR(line,19,1)  = ' ',
  166.         & SUBSTR(line,30,1)  = ' ',
  167.         & SUBSTR(line,36,1) ~= ' ', /* Exlude 'most downloaded' and 'top rated' files */
  168.         & slashposition > 20,
  169.         & slashposition < 29
  170.     THEN DO
  171.  
  172.       /* Change all comma to semicolon due to MUIRexx flaw */
  173.       line = TRANSLATE(line, ";", ",")
  174.  
  175.       /* This line must be edited if the format of the index file changes */
  176.       PARSE VAR line WITH 1 1 name +18 WITH 20 directory +10 WITH 31 size +4 WITH 36 comment
  177.  
  178.       LIST ID listid NODUP POS MUIV_List_Insert_Bottom INSERT STRING name","directory","size","comment
  179.     END
  180.   END
  181.  
  182.   list ID listid ATTRS MUIA_List_Quiet 0
  183.  
  184.   CALL CLOSE(indexhandle)
  185.  
  186. END
  187. ELSE DO
  188.   request ID RECSCRWIN TITLE '"File Error"' GADGETS "_OK" STRING "Cannot read file '"filename"'"
  189. END
  190.  
  191. RETURN
  192.  
  193.  
  194.  
  195. /* --------------------------------------------------------- */
  196. /* Save LST_SEL to AmiNet index file or user defined batch   */
  197. /* --------------------------------------------------------- */
  198.  
  199. savelist: PROCEDURE EXPOSE srcdir
  200.  
  201. MUIA_List_Entries         = '0x80421654'
  202. MUIM_Busy_Move            = '0x80020001'
  203. ASLFR_InitialFile         = '0x80080008'
  204. ASLFR_InitialDrawer       = '0x80080009'
  205.  
  206.  
  207. /* Get batchmode */
  208.  
  209. cycle ID CYC_BAT
  210. batchmode = RESULT
  211.  
  212. /* Save to AmiNet Index file ? */
  213.  
  214. IF batchmode = 'AmiNet Index' THEN DO
  215.   CALL saveasindex
  216.   RETURN
  217. END
  218.  
  219. /* An user configured batch mode is selected... */
  220.  
  221. /* Read global batchmode config in local stem */
  222.  
  223. IF loadbatchconfigs('['batchmode']') = 1 THEN DO
  224.  
  225.   locdir  = PATHPART(globalcfg.file)
  226.   locfile = FILEPART(globalcfg.file)
  227.  
  228.   OPTIONS FAILAT 11
  229.   aslrequest ID RECSCRWIN TITLE '"Save ''batchmode'' file ..."' ATTRS ASLFR_InitialDrawer locdir ASLFR_InitialFile locfile
  230.   returncode = RC
  231.   outputfilename   = RESULT
  232.   OPTIONS FAILAT 10
  233.  
  234.   IF returncode ~= 0 | outputfilename = '' THEN DO
  235.     RETURN
  236.   END
  237.  
  238.   IF OPEN(writehandle, outputfilename, 'W') THEN DO
  239.  
  240.     /* Read and Write batchmode intro file if available */
  241.  
  242.     filename = srcdir || "Configs/" || batchmode || ".intro"
  243.  
  244.     IF OPEN(handle, filename, 'R') THEN DO
  245.  
  246.       /* Do for all lines in file */
  247.       DO UNTIL EOF(handle)
  248.       
  249.         method ID CLS_BUSY MUIM_Busy_Move
  250.  
  251.         line = READLN(handle)
  252.  
  253.         /* Replace batch placeholders with value from config */
  254.         DO i=1 TO (batchcfg.0)
  255.  
  256.           /* Replace all placeholders in line */
  257.           start = POS(batchcfg.i.replace, line)
  258.           DO WHILE start ~= 0
  259.  
  260.             line  = SUBSTR(line,1,start-1) || SUBSTR(line,start+2)
  261.             line  = INSERT(batchcfg.i.val, line, start-1)
  262.             start = POS(batchcfg.i.replace, line)
  263.           END
  264.     
  265.         END
  266.  
  267.         CALL WRITELN(writehandle, line)
  268.       END
  269.  
  270.       CALL CLOSE(handle)
  271.     END
  272.  
  273.  
  274.     /* Read and Write batchmode entry file if available */
  275.  
  276.     filename = srcdir || "Configs/" || batchmode || ".entry"
  277.  
  278.     IF OPEN(handle, filename, 'R') THEN DO
  279.  
  280.       /* Add entry placeholders to local stem varaible */
  281.       i = batchcfg.0 + 1
  282.       batchcfg.i.replace = '%n'     /* name      */
  283.       i = i+1
  284.       batchcfg.i.replace = '%d'     /* directory */
  285.       i = i+1
  286.       batchcfg.i.replace = '%s'     /* size      */
  287.       i = i+1
  288.       batchcfg.i.replace = '%c'     /* comment   */
  289.       batchcfg.0 = i
  290.  
  291.       /* Read batchmode entry lines in local stem variable */
  292.  
  293.       entrycfg.0 = 0
  294.       i = 1
  295.  
  296.       DO UNTIL EOF(handle)
  297.   
  298.         method ID CLS_BUSY MUIM_Busy_Move
  299.  
  300.         entrycfg.i = READLN(handle)
  301.         entrycfg.0 = i
  302.         i = i + 1
  303.       END
  304.  
  305.       CALL CLOSE(handle)
  306.  
  307.       /* Do for all entries in LST_SEL */
  308.  
  309.       list ID LST_SEL ATTRS MUIA_List_Entries
  310.       lstselcount = RESULT
  311.  
  312.       IF lstselcount > 0 THEN DO
  313.  
  314.         DO lstselnr=0 TO lstselcount-1
  315.  
  316.           method ID CLS_BUSY MUIM_Busy_Move
  317.  
  318.           list ID LST_SEL POS lstselnr
  319.           listline = RESULT
  320.  
  321.           /* This line must be edited if the format of the index file changes */
  322.           PARSE VAR listline WITH 1 name +18 WITH 20 directory +10 WITH 31 size +4 WITH 36 comment
  323.  
  324.           /* Add entry values to local stem varaible */
  325.           i = batchcfg.0
  326.           batchcfg.i.val = comment
  327.           i = i-1
  328.           batchcfg.i.val = size
  329.           i = i-1
  330.           batchcfg.i.val = STRIP(directory)
  331.           i = i-1
  332.           batchcfg.i.val = STRIP(name)
  333.  
  334.  
  335.           DO global=0 TO globalcfg.readme  /* Process *.readme file ? */
  336.  
  337.             IF global=1 THEN DO
  338.  
  339.               i        = batchcfg.0 - 1    /* Set new 'size' to 0 */
  340.               batchcfg.i.val = '  0K'
  341.  
  342.               i        = batchcfg.0 - 3    /* Set new 'name' to *.readme */
  343.               position = LASTPOS('.', batchcfg.i.val)
  344.  
  345.               IF position ~= 0 THEN DO
  346.                 batchcfg.i.val = SUBSTR(batchcfg.i.val, 1, position) || "readme"
  347.               END
  348.               ELSE DO
  349.                 batchcfg.i.val = batchcfg.i.val || ".readme"
  350.               END
  351.             END
  352.  
  353.             /* Do for all entry config lines */
  354.  
  355.             DO entrycfgnr=1 TO entrycfg.0
  356.  
  357.               line = entrycfg.entrycfgnr
  358.  
  359.               /* Replace batch and entry placeholders with value from config */
  360.               DO i=1 TO batchcfg.0
  361.  
  362.                 /* Replace all placeholders in line */
  363.                 start = POS(batchcfg.i.replace, line)
  364.                 DO WHILE start ~= 0
  365.  
  366.                   line  = SUBSTR(line,1,start-1) || SUBSTR(line,start+2)
  367.                   line  = INSERT(batchcfg.i.val, line, start-1)
  368.                   start = POS(batchcfg.i.replace, line)
  369.                 END
  370.               END
  371.  
  372.               CALL WRITELN(writehandle, line)
  373.             END
  374.           END
  375.         END
  376.       END
  377.       batchcfg.0 = batchcfg.0 - 4  /* Remove entry variables from config */
  378.     END
  379.  
  380.  
  381.     /* Read and Write batchmode extro file if available */
  382.  
  383.     filename = srcdir || "Configs/" || batchmode || ".extro"
  384.  
  385.     IF OPEN(handle, filename, 'R') THEN DO
  386.  
  387.       /* Do for all lines in file */
  388.       DO UNTIL EOF(handle)
  389.       
  390.         method ID CLS_BUSY MUIM_Busy_Move
  391.  
  392.         line = READLN(handle)
  393.  
  394.         /* Replace batch placeholders with value from config */
  395.         DO i=1 TO (batchcfg.0)
  396.  
  397.           /* Replace all placeholders in line */
  398.           start = POS(batchcfg.i.replace, line)
  399.           DO WHILE start ~= 0
  400.  
  401.             line  = SUBSTR(line,1,start-1) || SUBSTR(line,start+2)
  402.             line  = INSERT(batchcfg.i.val, line, start-1)
  403.             start = POS(batchcfg.i.replace, line)
  404.           END
  405.         END
  406.  
  407.         CALL WRITELN(writehandle, line)
  408.       END
  409.  
  410.       CALL CLOSE(handle)
  411.     END
  412.  
  413.     CALL CLOSE(writehandle)
  414.  
  415.  
  416.     /* Copy icon for batchfile if available */
  417.     allfiles = showdir(srcdir || 'Configs', 'f', ';')
  418.  
  419.     IF INDEX(allfiles, batchmode".info") ~= 0 THEN DO
  420.       ADDRESS COMMAND 'copy >NIL: "'srcdir'Configs/'batchmode'.info" "'outputfilename'.info"'
  421.     END
  422.  
  423.  
  424.     /* Replace all filename placeholder in commandline */
  425.     cmd_string = globalcfg.cmd
  426.  
  427.     start = POS("%o", cmd_string)
  428.     DO WHILE start ~= 0
  429.       cmd_string  = SUBSTR(cmd_string,1,start-1) || SUBSTR(cmd_string,start+2)
  430.       cmd_string  = INSERT(outputfilename, cmd_string, start-1)
  431.       start = POS("%o", cmd_string)
  432.     END
  433.  
  434.  
  435.     SELECT
  436.  
  437.       WHEN globalcfg.exec = 'Never' THEN DO
  438.       END
  439.  
  440.       WHEN globalcfg.exec = 'Always' THEN DO
  441.         OPTIONS FAILAT 21
  442.         ADDRESS COMMAND cmd_string
  443.         OPTIONS FAILAT 10
  444.       END
  445.  
  446.       OTHERWISE DO
  447.  
  448.         request ID RECSCRWIN TITLE 'Execute?' GADGETS '_OK|_Cancel' STRING 'Process output via\n\n\033b'cmd_string'\033n\n\ncommand now?'
  449.  
  450.         IF RESULT = 1 THEN DO
  451.           OPTIONS FAILAT 21
  452.           ADDRESS COMMAND cmd_string
  453.           OPTIONS FAILAT 10
  454.         END
  455.       END
  456.     END
  457.  
  458.   END
  459.   ELSE DO
  460.     request ID RECSCRWIN TITLE '"File Error"' GADGETS "_OK" STRING "'Cannot write file '"filename"'"
  461.   END
  462.  
  463. END
  464. ELSE DO
  465.   request ID RECSCRWIN TITLE '"File Error"' GADGETS '"_OK"' STRING "Cannot read '"batchmode"' configuration"
  466. END
  467.  
  468. RETURN
  469.  
  470.  
  471.  
  472. /* --------------------------------------------------------- */
  473. /* Save all entries from the LST_SEL to an AmiNet index file */
  474. /* --------------------------------------------------------- */
  475.  
  476. saveasindex: PROCEDURE EXPOSE srcdir
  477.  
  478. MUIA_List_Entries         = '0x80421654'
  479. MUIM_Busy_Move            = '0x80020001'
  480. ASLFR_InitialFile         = '0x80080008'
  481. ASLFR_InitialDrawer       = '0x80080009'
  482.  
  483.  
  484. OPTIONS FAILAT 11
  485. aslrequest ID RECSCRWIN TITLE '"Save selected files..."' ATTRS ASLFR_InitialDrawer srcdir ASLFR_InitialFile "RecentScript.lst"
  486. returncode = RC
  487. filename   = RESULT
  488. OPTIONS FAILAT 10
  489.  
  490. IF returncode = 0 & filename ~= '' THEN DO
  491.  
  492.   IF OPEN(handle, filename, 'W') THEN DO
  493.  
  494.     list ID LST_SEL ATTRS MUIA_List_Entries
  495.     number = RESULT
  496.  
  497.     IF number > 0 THEN DO
  498.  
  499.       DO i=0 TO number-1
  500.  
  501.         method ID CLS_BUSY MUIM_Busy_Move
  502.  
  503.         list ID LST_SEL POS i
  504.         line = RESULT
  505.  
  506.         /* This line must be edited if the format of the index file changes */
  507.         PARSE VAR line WITH 1 name +18 WITH 20 directory +10 WITH 31 size +4 WITH 36 comment
  508.  
  509.         CALL WRITELN(handle,name directory size comment)
  510.       END
  511.     END
  512.  
  513.     CALL CLOSE(handle)
  514.   END
  515.   ELSE DO
  516.     request ID RECSCRWIN TITLE '"File Error"' GADGETS "_OK" STRING "'Cannot write file '"filename"'"
  517.   END
  518. END
  519.  
  520.  
  521. RETURN
  522.  
  523.  
  524.  
  525. /* --------------------------------------------------------- */
  526. /* Delete all entries in specified listview                  */
  527. /* --------------------------------------------------------- */
  528.  
  529. clearlist: PROCEDURE
  530.  
  531. parse arg listid
  532.  
  533. list ID listid STRING
  534.  
  535. RETURN
  536.  
  537.  
  538.  
  539. /* --------------------------------------------------------- */
  540. /* (De)Select entries in LST_ALL with search string          */
  541. /* --------------------------------------------------------- */
  542.  
  543. patternentries: PROCEDURE
  544.  
  545. parse arg mode
  546.  
  547. MUIA_List_Entries         = '0x80421654'
  548. MUIM_List_Select          = '0x804252d8'
  549. MUIM_Busy_Move            = '0x80020001'
  550.  
  551. list ID LST_ALL ATTRS MUIA_List_Entries
  552. number = RESULT
  553.  
  554. string ID STR_PATT
  555. pattern = UPPER(RESULT)
  556.  
  557. IF number > 0 THEN DO
  558.  
  559.   DO i=0 TO number-1
  560.  
  561.     method ID CLS_BUSY MUIM_Busy_Move
  562.  
  563.     list ID LST_ALL POS i
  564.     line = UPPER(RESULT)
  565.  
  566.     IF POS(pattern, line) ~= 0 THEN DO
  567.  
  568.       method ID LST_ALL MUIM_List_Select i mode 0
  569.     END
  570.   END
  571. END
  572.  
  573. RETURN
  574.  
  575.  
  576.  
  577. /* --------------------------------------------------------- */
  578. /* Opens batch settings window for the specified batchmode   */
  579. /* --------------------------------------------------------- */
  580.  
  581. batchsettingopen: PROCEDURE EXPOSE portname srcdir
  582.  
  583. parse arg '['batchmode']'
  584.  
  585. Selected                  = '0x8042654b'
  586. MUIA_Weight               = '0x80421d1f'
  587.  
  588. /* GUI Help Bubbles */
  589.  
  590. HLP_BUT_DESC   = '"Shows batchmode description if available"'
  591. HLP_CHK_README = '"Generate additional entry for the ''.readme'' file ?"'
  592. HLP_ASL_FILE   = '"Defines default filename for saving.\nDo NOT use Spaces!"'
  593. HLP_CYC_EXEC   = '"Defines whether the script should\nbe started after saving"'
  594. HLP_ASL_CMD    = '"Defines the DOS command to execute the output.\nVariable ''%o'' will be replaced by path and name of the output."'
  595.  
  596. /* GUI Commands */
  597.  
  598. CMD_BUT_OK     = '"'srcdir'RecentScriptCmd 'portname' SETBATHDL OK     ['batchmode']"'
  599. CMD_BUT_CANCEL = '"'srcdir'RecentScriptCmd 'portname' SETBATHDL CANCEL ['batchmode']"'
  600. CMD_BUT_DESC   = '"'srcdir'RecentScriptCmd 'portname' SETBATHDL DESC   ['batchmode']"'
  601.  
  602.  
  603. /* Read global batchmode config in local stem vraiable */
  604.  
  605. IF loadbatchconfigs('['batchmode']') = 1 THEN DO
  606.  
  607.   asdf = 'endgroup'  /* Workaround for an interpreting error (?) */
  608.  
  609.   /* Create window */
  610.  
  611.   window ID BATSETWIN TITLE '"Settings for '''batchmode'''"' PORT portname
  612.  
  613.     button COMMAND CMD_BUT_DESC HELP HLP_BUT_DESC LABEL 'Description...' 
  614.  
  615.     group FRAME LABEL 'Global'
  616.       group HORIZ
  617.         space HORIZ
  618.         check ID CHK_README STRINGS '"0,1"' ATTRS Selected globalcfg.readme HELP HLP_CHK_README
  619.         label  "Include '#?.readme'"
  620.         space HORIZ
  621.       endgroup
  622.       group HORIZ
  623.         label  "Save to"
  624.         popasl ID ASL_FILE HELP HLP_ASL_FILE CONTENT globalcfg.file
  625.       endgroup
  626.       group HORIZ
  627.         cycle ATTRS MUIA_Weight 0 ID CYC_EXEC HELP HLP_CYC_EXEC LABELS 'Never,Ask,Always'
  628.         label  "execute script via"
  629.         popasl ID ASL_CMD HELP HLP_ASL_CMD CONTENT globalcfg.cmd
  630.       endgroup
  631.     endgroup
  632.  
  633.     group FRAME SCROLL LABEL 'Variables'
  634.  
  635.       /* Create string gadgets for each user variable */
  636.  
  637.       DO i=1 TO batchcfg.0
  638.         group ID '"G'D2C(i+65)'"'
  639.           label CENTER '"'batchcfg.i.desc'"'
  640.           group HORIZ
  641.             label batchcfg.i.replace
  642.             string ID '"S'D2C(i+65)'"' HELP '"Replaces configuration variable ''%'D2C(i+48)''' in output"' CONTENT batchcfg.i.val
  643.           interpret asdf
  644.         interpret asdf
  645.       END i
  646.  
  647.     endgroup
  648.  
  649.     group HORIZ
  650.       button COMMAND CMD_BUT_OK     LABEL 'OK'
  651.       button COMMAND CMD_BUT_CANCEL LABEL 'Cancel'
  652.     endgroup
  653.  
  654.   endwindow
  655.  
  656.   cycle ID CYC_EXEC LABELS globalcfg.exec
  657.  
  658. END
  659. ELSE DO
  660.   request ID RECSCRWIN TITLE '"File Error"' GADGETS '"_OK"' STRING "Cannot read '"batchmode"' configuration"
  661. END
  662.  
  663. RETURN
  664.  
  665.  
  666.  
  667. /* --------------------------------------------------------- */
  668. /* Handle buttons from the batch settings window             */
  669. /* --------------------------------------------------------- */
  670.  
  671. batchsettinghandle: PROCEDURE expose srcdir portname
  672.  
  673. parse arg mode '['batchmode']'
  674.  
  675. MUIM_Busy_Move            = '0x80020001'
  676. MUIA_Frame                = '0x8042ac64'
  677. MUIA_Font                 = '0x8042be50'
  678. MUIA_List_Quiet           = '0x8042d8c7'
  679. MUIV_Frame_ReadList       =  5
  680. MUIV_List_Insert_Bottom   = -3
  681. MUIV_Font_Fixed           = -4
  682.  
  683. SELECT
  684.  
  685.   WHEN mode = 'DESC' THEN DO
  686.  
  687.    window ID HELPWIN CLOSE
  688.  
  689.    window ID HELPWIN TITLE '"Description of '''batchmode'''"' COMMAND '"window ID HELPWIN CLOSE"' PORT portname
  690.  
  691.      filename = srcdir || "Configs/" || batchmode || ".hlp"
  692.  
  693.      IF OPEN(handle, filename, 'R') THEN DO
  694.        view ID HELPVIEW FILE '"'filename'"'
  695.        CALL CLOSE(handle)
  696.      END
  697.      ELSE DO
  698.        view ID HELPVIEW STRING "Sorry, no help available.\n\nContact the author of the configuration to provide it..."
  699.      END
  700.  
  701.    endwindow
  702.   END
  703.  
  704.  
  705.   WHEN mode = 'CANCEL' THEN DO
  706.     window ID BATSETWIN CLOSE
  707.   END
  708.  
  709.   WHEN mode = 'OK' THEN DO
  710.  
  711.     /* Save global and variable configs to file */
  712.  
  713.     /* Read global config for description in local stem */
  714.  
  715.     IF loadbatchconfigs('['batchmode']') = 1 THEN DO
  716.  
  717.       /* Get new global config values in local stem */
  718.  
  719.       check ID CHK_README
  720.       globalcfg.readme = RESULT
  721.       popasl ID ASL_FILE
  722.       globalcfg.file = RESULT
  723.       cycle ID CYC_EXEC
  724.       globalcfg.exec = RESULT
  725.       popasl ID ASL_CMD
  726.       globalcfg.cmd = RESULT
  727.  
  728.       /* Write global config to file */
  729.  
  730.       filename = srcdir || "Configs/" || batchmode || ".cfg"
  731.  
  732.       IF OPEN(handle, filename, 'W') THEN DO
  733.         CALL WRITELN(handle, globalcfg.readme)
  734.         CALL WRITELN(handle, globalcfg.file)
  735.         CALL WRITELN(handle, globalcfg.exec)
  736.         CALL WRITELN(handle, globalcfg.cmd)
  737.         CALL CLOSE(handle)
  738.       END
  739.       ELSE DO
  740.         request ID RECSCRWIN TITLE '"File Error"' GADGETS '"_OK"' STRING "Cannot write file '"filename"'"
  741.       END
  742.  
  743.  
  744.       filename = srcdir || "Configs/" || batchmode || ".var"
  745.  
  746.       /* Write variable batchmode config to file */
  747.  
  748.       IF OPEN(handle, filename, 'W') THEN DO
  749.  
  750.         DO i=1 TO batchcfg.0
  751.  
  752.           method ID CLS_BUSY MUIM_Busy_Move
  753.  
  754.           string ID '"S'D2C(i+65)'"'
  755.           batchcfg.i.val = RESULT
  756.  
  757.           CALL WRITELN(handle, batchcfg.i.desc)
  758.           CALL WRITELN(handle, batchcfg.i.val)
  759.         END
  760.  
  761.         CALL CLOSE(handle)
  762.       END
  763.       ELSE DO
  764.         request ID RECSCRWIN TITLE '"File Error"' GADGETS '"_OK"' STRING "Cannot write file '"filename"'"
  765.       END
  766.     END
  767.     ELSE DO
  768.       request ID RECSCRWIN TITLE '"File Error"' GADGETS '"_OK"' STRING "Cannot read '"batchmode"' configuration"
  769.     END
  770.  
  771.     window ID BATSETWIN CLOSE
  772.   END
  773.  
  774.   OTHERWISE DO
  775.     request ID RECSCRWIN TITLE '"Internal Error"' GADGETS '"_OK"' STRING '"Unsupport command 'mode'"'
  776.   END
  777. END
  778.  
  779. RETURN
  780.  
  781.  
  782.  
  783. /* --------------------------------------------------------- */
  784. /* Load global and variable configuration for batchmode      */
  785. /* --------------------------------------------------------- */
  786.  
  787. loadbatchconfigs: PROCEDURE EXPOSE srcdir globalcfg. batchcfg.
  788.  
  789. parse arg '['batchmode']'
  790.  
  791. /* Read global batchmode config in local stem vraiable */
  792.  
  793. filename = srcdir || "Configs/" || batchmode || ".cfg"
  794.  
  795. IF OPEN(handle, filename, 'R') THEN DO
  796.  
  797.   globalcfg.readme = READLN(handle)
  798.   globalcfg.file   = READLN(handle)
  799.   globalcfg.exec   = READLN(handle)
  800.   globalcfg.cmd    = READLN(handle)
  801.  
  802.   CALL CLOSE(handle)
  803.  
  804.  
  805.   /* Read variable batchmode config in local stem variable */
  806.  
  807.   filename = srcdir || "Configs/" || batchmode || ".var"
  808.  
  809.   batchcfg.0 = 0
  810.  
  811.   IF OPEN(handle, filename, 'R') THEN DO
  812.  
  813.     i = 0
  814.  
  815.     DO UNTIL EOF(handle)
  816.  
  817.       method ID CLS_BUSY MUIM_Busy_Move
  818.  
  819.       description = READLN(handle)
  820.       value       = READLN(handle)
  821.  
  822.       IF description ~= '' & value ~= '' THEN DO
  823.  
  824.         i = i + 1
  825.         batchcfg.0 = i
  826.  
  827.         batchcfg.i.replace = '%'D2C(i+48)''   /* %1 ... */
  828.         batchcfg.i.desc    = description
  829.         batchcfg.i.val     = value
  830.       END
  831.     END
  832.  
  833.     CALL CLOSE(handle)
  834.   END
  835.  
  836.   RETURN 1
  837.  
  838. END
  839. ELSE DO
  840.   request ID RECSCRWIN TITLE '"File Error"' GADGETS '"_OK"' STRING "Cannot read file '"filename"'"
  841.   RETURN 0
  842. END
  843.  
  844.  
  845. /* --------------------------------------------------------- */
  846. /* Only a testprocedure for testing new features             */
  847. /* --------------------------------------------------------- */
  848.  
  849. testprocedure: PROCEDURE
  850.  
  851. RETURN
  852.